package com.hcms.system.service.impl;

import com.hcms.system.dao.RoleMenuDao;
import com.hcms.system.domain.RoleMenuDo;
import com.hcms.system.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RoleMenuServiceImpl implements RoleMenuService {

    @Autowired
    RoleMenuDao roleMenuMapper;

    @Override
    public boolean isExistMenu(int roleId, int menuId) {
        RoleMenuDo roleMenu = new RoleMenuDo();
        roleMenu.setRoleId(roleId);
        roleMenu.setMenuId(menuId);
        int count = roleMenuMapper.isExistMenu(roleMenu);
        return count > 0;
    }

    @Override
    public List<RoleMenuDo> listByRoleId(int roleId) {
        List<RoleMenuDo> roleMenus = roleMenuMapper.listByRoleId(roleId);
        return roleMenus;
    }

    @Override
    public int save(RoleMenuDo roleMenu) {
        Date date = new Date();
        roleMenu.setCreateTime(date);
        roleMenu.setUpdateTime(date);
        int count = roleMenuMapper.save(roleMenu);
        return count;
    }

    @Override
    public int update(RoleMenuDo roleMenu) {
        roleMenu.setUpdateTime(new Date());
        int count = roleMenuMapper.update(roleMenu);
        return count;
    }
}
